package com.xmj.web.controller.ms;

import com.xmj.common.annotation.Log;
import com.xmj.common.core.controller.BaseController;
import com.xmj.common.core.domain.AjaxResult;
import com.xmj.common.core.page.TableDataInfo;
import com.xmj.common.enums.BusinessType;
import com.xmj.common.utils.poi.ExcelUtil;
import com.xmj.ms.domain.ServiceTypes;
import com.xmj.ms.service.IServiceTypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务Controller
 *
 * @author ohh
 * @date 2024-04-21
 */
@RestController
@RequestMapping("/ms/ServiceTypes")
public class ServiceTypesController extends BaseController
{
    @Autowired
    private IServiceTypesService serviceTypesService;

    /**
     * 查询服务列表
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceTypes serviceTypes)
    {
        startPage();
        List<ServiceTypes> list = serviceTypesService.selectServiceTypesList(serviceTypes);
        return getDataTable(list);
    }

    /**
     * 导出服务列表
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:export')")
    @Log(title = "服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceTypes serviceTypes)
    {
        List<ServiceTypes> list = serviceTypesService.selectServiceTypesList(serviceTypes);
        ExcelUtil<ServiceTypes> util = new ExcelUtil<ServiceTypes>(ServiceTypes.class);
        util.exportExcel(response, list, "服务数据");
    }

    /**
     * 获取服务详细信息
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:query')")
    @GetMapping(value = "/{servicetypeID}")
    public AjaxResult getInfo(@PathVariable("servicetypeID") Long servicetypeID)
    {
        return success(serviceTypesService.selectServiceTypesByServicetypeID(servicetypeID));
    }

    /**
     * 新增服务
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:add')")
    @Log(title = "服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceTypes serviceTypes)
    {
        return toAjax(serviceTypesService.insertServiceTypes(serviceTypes));
    }

    /**
     * 修改服务
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:edit')")
    @Log(title = "服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceTypes serviceTypes)
    {
        return toAjax(serviceTypesService.updateServiceTypes(serviceTypes));
    }

    /**
     * 删除服务
     */
    @PreAuthorize("@ss.hasPermi('ms:ServiceTypes:remove')")
    @Log(title = "服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{servicetypeIDs}")
    public AjaxResult remove(@PathVariable Long[] servicetypeIDs)
    {
        return toAjax(serviceTypesService.deleteServiceTypesByServicetypeIDs(servicetypeIDs));
    }
}
